package com.ylsk.flowable.domain.vo;

import com.google.common.collect.Lists;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

/**
 * 分页封装类
 */

public class Page<T> implements Serializable,Iterable<T> {


    /**
     * 每页记录数
     */

    private int limit=10;




    /**
     * 分页的结果集
     */

    private List<T> rows= Lists.newArrayList();


    /**
     * 总条数
     */

    private Long total;


    /**
     * 分页偏移量
     */

    private int offset=0;






    /**
     *过滤条件
     */
    private String flowQuery;


    /**
     * 过滤条件集合
     */
    private List<FlowQuery> flowQueries;


    /**
     * 流程定义ID
     */
    private String processDefinitionId;


    /**
     * 操作类型
     */
    private String opereateType;


    public Page(){

    }

    public Page(int offset, int pageSize){
        this.offset = offset;
    }





    public List<T> getRows() {
        return rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
        if(limit < 1){
            this.limit = 1;
        }
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }


    public int getOffset() {
        return offset>=1?offset-1:0;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public String getOpereateType() {
        return opereateType;
    }

    public void setOpereateType(String opereateType) {
        this.opereateType = opereateType;
    }

    /**
     * Returns an iterator over elements of type {@code T}.
     *
     * @return an Iterator.
     */
    @Override
    public Iterator<T> iterator() {
        return ((List<T>)rows).iterator();
    }




    public String getFlowQuery() {
        return flowQuery;
    }

    public void setFlowQuery(String flowQuery) {
        this.flowQuery = flowQuery;
    }

    public String getProcessDefinitionId() {
        return processDefinitionId;
    }

    public void setProcessDefinitionId(String processDefinitionId) {
        this.processDefinitionId = processDefinitionId;
    }


    public List<FlowQuery> getFlowQueries() {
        return flowQueries;
    }

    public void setFlowQueries(List<FlowQuery> flowQueries) {
        this.flowQueries = flowQueries;
    }
}
